package com.dg.cuckoo.admin.service.impl;

import com.dg.cuckoo.admin.dto.projectInfo.ProjectLogDto;
import com.dg.cuckoo.admin.repository.FileRepository;
import com.dg.cuckoo.admin.repository.ProjectLogRepository;
import com.dg.cuckoo.admin.service.CompletedService;
import com.dg.cuckoo.admin.service.ProjectInfoServer;
import com.dg.cuckoo.admin.service.ProjectLogService;
import com.dg.cuckoo.common.utils.PageModel;
import com.dg.cuckoo.core.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@Service
public class CompletedServiceimpl implements CompletedService {

    @Autowired
    private ProjectLogService service;
    @Autowired
    private ProjectLogRepository repository;
    @Autowired
    private ProjectInfoServer projectInfoServer;
    @Autowired
    private FileRepository fileRepository;

    @Override
    public void save(ProjectLogDto dto, MultipartFile[] files) throws Exception {
        savecheck(dto);
        ProjectLogDto save = repository.save(dto);
        if(files!=null){
            projectInfoServer.powerfulFileSave(files,save.getId());
        }
    }

    @Override
    public PageModel page(Integer page, Integer pageSize) {
        Integer one = page;
        page = (page - 1) * pageSize;
        int size = repository.findAll().size();
        List<ProjectLogDto> list = repository.page(2,page, pageSize);
        return new PageModel(one,pageSize,size,list);
    }

    @Override
    public void updata(String id, ProjectLogDto dto, MultipartFile[] files) throws Exception {
        if(id==null){
            throw new ServiceException("请选择行");
        }
        dto.setType(2);
        savecheck(dto);
        ProjectLogDto save = repository.save(dto);
        if(files.length>0){
            fileRepository.deleteAll(fileRepository.findByByMark(id));
            projectInfoServer.powerfulFileSave(files,save.getId());
        }
    }

    public void savecheck(ProjectLogDto dto){

    }
}
